package com.logistics.controller;

import com.alibaba.fastjson.JSON;
import com.logistics.pojo.Employee;
import com.logistics.util.JwtUtil;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//基础控制器
public class BaseController {

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private HttpServletResponse response;

    //获取当前用户信息
    public Employee getUser() {

        //获取token
        String token = request.getHeader("token");
        //解析token
        Claims claims = JwtUtil.parseJWT(token);
        String jsonEmp = claims.getSubject();
        return JSON.parseObject(jsonEmp,Employee.class);

    }

}
